package community;

import javax.servlet.http.*;

import model.*;

import org.apache.struts.action.*;

import util.*;

public class CommunityMain extends Action{
	//커뮤니티 선택시 실행되는 메소드(커뮤니티메인화면 구성)
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		CommunityDAO coDAO = new CommunityDAO();
		MemberCommunityDAO mcDAO = new MemberCommunityDAO();
		
		CommunityForm coForm = (CommunityForm)form;
		
		HttpSession session = request.getSession();
		User user = (User)session.getAttribute("user");
		
		//User가 로그인 했으면 가입된 커뮤니티 목록을
		//User가 로그인 안했으면 빈 목록
		if(session.getAttribute("user")!=null){
			if(user.isLogon()){
				coForm.setMemberCommunitys(mcDAO.getMemberCommunity(user.getMid()));
			}else{
				coForm.setMemberCommunitys(mcDAO.getMemberCommunity());
			}
		}
		
		//신설동호회 정보를 셋팅
		coForm.setNewCommunity(coDAO.getNewCommunityList());
		//인기동호회 정보를 셋팅
		coForm.setPopulCommunity(coDAO.getPopulCommunityList());
		//종류별 커뮤니티 정보를 셋팅
		coForm.setSortCommunity(coDAO.getSortCommunityList());
		
		//금주의 동호회 셋팅
		Community community = coDAO.getNewCommunity();
		coForm.setCono(community.getCono());
		coForm.setConame(community.getConame());
		coForm.setCoopen(community.getCoopen());
		coForm.setCoregdate(community.getCoregdate());
		coForm.setCologoofn(community.getCologoofn());
		coForm.setCologosfn(community.getCologosfn());
		coForm.setCopoptext(community.getCopoptext());
		coForm.setCopopwidth(community.getCopopwidth());
		coForm.setCopopheight(community.getCopopheight());
		coForm.setCoguide(community.getCoguide());
		coForm.setCcno(community.getCcno());
		coForm.setCount(mcDAO.countCommunityMembers(coForm.getCono()));
		coForm.setMcnick(mcDAO.getCommunityMcnick(coForm.getCono()));
		coForm.setMid(mcDAO.getCommunityMid(coForm.getCono()));
				
		return mapping.findForward("ok");
	}	

}
